package day_2022_7_to_8.day48;

/**
 * @author haomin
 * @date 2022/08/21 20:47
 **/
public class Day36_7_Num81_Search {
    class Solution {
        public boolean search(int[] nums, int target) {
            int left = 0, right = nums.length-1, mid;
            while(left <= right){
                mid = left + ((right - left)>>1);

                if(nums[mid] == target) return true;
                if (nums[mid] > nums[left]){
                    if (nums[left] <= target && target < nums[mid]) right = mid - 1;
                    else left = mid + 1;
                }else if (nums[mid] < nums[left]){
                    if (nums[mid] < target && target <= nums[right]) left = mid + 1;
                    else right = mid - 1;
                }else left += 1;
            }
            return false;
        }
    }
}